<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card  >
        <el-tabs>
          <!-- 放置页签 -->
          <el-tab-pane label="角色管理">
            <!-- 新增角色按钮 -->
            <el-row style="height:60px">
              <el-button
                icon="el-icon-plus"
                size="small"
                type="primary"
                >新增角色</el-button>
            </el-row>
            <!-- 表格 -->
            <el-table border="" :data="list">
                <el-table-column type="index" align="center" label="序号" width="120" />
                <el-table-column align="center" property="name" label="角色名称" width="240" />
                <el-table-column align="center" property="description" label="描述" />
                <el-table-column align="center" label="操作" >
                <template slot-scope="{ row }">
                  <el-button size="small" type="success">分配权限</el-button>
                  <el-button size="small" type="primary">编辑</el-button>
                  <el-button size="small" type="danger" @click="deleteRole(row.id)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!-- 分页组件 -->
            <el-row type="flex" justify="center" style="margin-top: 30px">
              <el-pagination
              :current-page="page.page"
              :page-size="page.pagesize"
              :total="page.total"
              @current-change="changepage"
              layout="prev, pager, next" />
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="公司信息">
            <el-alert
            title="对公司名称、公司地址、营业执照、公司地区的更新，将使得公司资料被重新审核，请谨慎修改"
            type="info"
            show-icon
            :closable='false'
            />
            <el-form label-width="120px" style="margin-top:50px">
              <el-form-item  label="公司名称">
                <el-input v-model="FormData.name" disabled style="width:400px" />
              </el-form-item>
              <el-form-item label="公司地址">
                <el-input v-model="FormData.companyAddress" disabled style="width:400px"/>
              </el-form-item>
              <el-form-item disabled label="邮箱">
                <el-input v-model="FormData.mailbox" disabled style="width:400px"/>
              </el-form-item>
              <el-form-item  label="备注">
                <el-input v-model="FormData.remarks" disabled style="width:400px" type="textarea" :rows="3"/>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </el-card >
    </div>
  </div>
</template>

<script>
import { getRoleList, getCompanyInfo, deleteRole } from '@/api/setting'
import { mapGetters } from 'vuex'
export default {
  data () {
    return {
      list: [], // 接受数组数据
      page: {
        page: 1, // 页码
        pagesize: 10,
        total: 0 // 记录总数
      },
      FormData: {} // 公司信息
    }
  },
  created () {
    this.getRoleList()
    this.getCompanyInfo()
  },
  computed: {
    ...mapGetters(['companyId']) // 得到快捷访问中需要的 ID
  },
  methods: {
    async getRoleList () {
      const { total, rows } = await getRoleList(this.page)
      this.page.total = total
      this.list = rows
    },
    changepage (newPage) {
      // newPage当前点击的页码
      this.page.page = newPage // 当前页码赋值给当前的最新页码
      this.getRoleList() // 重新调用数据
    },
    async getCompanyInfo () {
    this.FormData = await getCompanyInfo(this.companyId)
    console.log(FormData)
  },
  async deleteRole(id){
    await this.$confirm('确定删除该角色吗')
    try {
      await deleteRole(id) // 调用删除接口 id --> 利用插槽解构出数据
      this.getRoleList() // 重新获取角色列表
      this.$message.success('删除成功') // 提示消息
    } catch (error) {
      console.log(erro)
    }
  }
  }
}
</script>

<style>

</style>
